﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace Palsta.Core
{
    public class XslHTML : XslElement
    {
        /*
         * Constructors
         */
        public XslHTML(XmlNode xslNode)
        {
            _jsFunctionName = "";
            _xmlNode = xslNode;
        }

        /*
         * Overrides
         */ 
        public override String GetFunctionDeclareScript()
        {
            return "";
        }

        /*
         * New functions
         */ 

        public virtual String GetHTMLStart()
        {
            if (_xmlNode.NodeType == XmlNodeType.Text) return _xmlNode.Value.Trim();
            String result = "";
            String id = _xmlNode.Attributes["xd:binding"] != null ? _xmlNode.Attributes["xd:binding"].Value : null;
            if (id != null)
            {
                XmlAttribute  elementId = _xmlNode.OwnerDocument.CreateAttribute("id");
                elementId.Value = id;
                _xmlNode.Attributes.Append(elementId);
            }
            if (_xmlNode.Name.ToLower() == "span" && _xmlNode.Attributes["class"].Value.ToLower() == "xdtextbox")
            {
                result = "<input";
            }
            else
            {
                result = "<" + _xmlNode.Name;
            }
            foreach (XmlAttribute attribute in _xmlNode.Attributes)
            {
                result += " " + attribute.Name + "=\"" + attribute.Value + "\" ";
            }
            result += ">";
            return result;
        }

        public virtual String GetHTMLEnd()
        {
            if (_xmlNode.NodeType == XmlNodeType.Text) return "";
            return "</" + _xmlNode.Name + ">";
        }
    }
}
